sex="男"
id = input('请输入ID：')
for i in id[0:]:
    if not(i.isalnum() or i == '_'):
        print('id名%s不合法' %id)
        break
if len(id)>8:
    print("id长度超过8位")
email = input("请输入email：")

identity=input("请输入身份证号：")
sign = True
with open("user.txt", mode="a+", encoding="utf-8") as fp:
    while sign:
        # 输入用户名
        username = input("请输入要注册的用户名:")
        if username == "" or " " in username:
            print("对不起,该名字含有非法字符")
        else:
            id_card = input('请输入身份证号码：')
            jy = id_card[-1]
            if len(id_card) == 18:
                x = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
                s = 0
                # print(list(zip(x,id_card)))
                s = sum(list(map(lambda a, b: a * b, x, map(int, id_card[0:-1]))))
                b = s % 11
                y = ("1", "O", "X", "9", "8", "7", "6", "5", "4", "3", "2")
                c = y[b]
                if jy != c:
                    print('经计算校验码为', c, '和实际不同，身份证不合法！')
                else:
                    print('经计算校验码为', c, '和实际相同,身份证合法！')
                    name = input("请输入姓名：")
                    if name.decode("utf-8")<2 or name.decode("utf-8")>8:
                        print('名字不合法')
                    else:
                        print('注册成功')
            else:
                print('身份证位数不对')
name=input("请输入姓名：")
if len(name)>4:
    print("输入的名字过长")
for i in name[0:]:
    if i=="!"or i=="@" or i=="#" or i=="$" or i=="%" or i=="^" or i=="&" or i.isalnum():
        print('姓名%s不合法' %id)
        break

print("注册用户ID为：",id,"姓名为：",name,"性别为：",sex,"email为：",email,{ },"身份证号为：",identity)